<?php


namespace App\Services;


use App\Models\Users;

class ClassStudentService extends BaseService
{

    /**
     * 获取班级学生列表
     * @return
     */
    public function listClassStudent($username,$school_id,$class_grades_id,$page,$limit,$sort,$order) {
        $query = Users::leftJoin('class_students', 'class_students.users_id', '=', 'users.id')
                      ->leftJoin('schools', 'schools.id', '=', 'users.school_id')
                      ->leftJoin('class_grades', 'class_grades.id', '=', 'class_students.class_grades_id')
                      ->select('users.*','schools.name as school_name','class_grades.name as class_name'
                          ,'class_grades.id as class_grades_id','users.school_id')
                    ->where('users.type',0);
        if(!empty($username)){
            $query->where('username','like',"%$username%");
        }
        if(!empty($school_id)){
            $query->where('users.school_id',$school_id);
        }
        if(!empty($class_grades_id)){
            $query->where('class_grades_id',$class_grades_id);
        }


        return $query->orderBy($sort,$order)->paginate($limit, ['*'], 'page', $page);
    }
}
